package com.gxx.articlecomment.controller;

import com.gxx.articlecomment.entity.Comment;
import com.gxx.articlecomment.service.CommentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;

@Controller
public class CommentController {

    @Resource
    private CommentService commentService;


    @GetMapping("/selectComment")
    public String findAll(Model model) {
        model.addAttribute("list",commentService.findAll());
        return "commentList";
    }

    @PostMapping("/add")
    public String addComment(Comment comment){
        commentService.saveComment(comment);
        return "redirect:/selectComment";
    }

    @PostMapping("/update")
    public String updateComment(Comment comment){
        commentService.updateComment(comment);
        return "redirect:/selectComment";
    }


    @GetMapping("/del")
    public String deleteComment(String id){
        commentService.deleteCommentById(id);
        return "redirect:/selectComment";
    }

}
